package org.example.multi_sys_consist.module;

import com.alibaba.fastjson.JSONObject;
import org.example.multi_sys_consist.constant.TransactionJobType;
import org.example.multi_sys_consist.pojo.entity.TransactionJob;
import org.example.multi_sys_consist.remote.FinanceLogSystemService;
import org.example.multi_sys_consist.service.FinanceLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static org.example.multi_sys_consist.constant.TransactionJobType.PUSH_FINANCE_LOG;

@Component
public class PushFinanceLogExecutor implements TransactionJobExecutor {

    @Autowired
    private FinanceLogService financeLogService;
    @Autowired
    private FinanceLogSystemService financeLogSystemService;

    @Override
    public void execute(TransactionJob job) {
        JSONObject jo = JSONObject.parseObject(job.getData());
        financeLogSystemService.pushFinanceLog(financeLogService.getByApplyId(jo.getLong("applyId")));
    }

    @Override
    public TransactionJobType type() {
        return PUSH_FINANCE_LOG;
    }
}
